<!--
 @description  关键字搜索统计
 @fileName index.vue
 @author zengqiongying
 @created 2024/05/09 14:24:22
-->
<template>
  <div>
    <table-box
      ref="refTable"
      :selected-arry.sync="tableSelected"
      :table-config="tableConfig"
      :other-filters="otherFilters"
      :off-set="-10"
      table-row-key="id"
      :show-custom-collect="true"
      :show-custom-combine="true"
      :show-custom-setting="false"
      :setting-auto-request="false"
      :table-sortable="false"
      @btnOperate="btnOperate"
    />
    <export-files
      v-if="exportVisible"
      title="关键字搜索统计导出"
      :visible.sync="exportVisible"
      :config="exportConfig"
    />
  </div>
</template>

<script>
import { parseTime } from '@/utils'
export default {
  name: 'SearchKeyWordRecord',
  components: {},
  filters: {},
  mixins: [],
  data() {
    return {
      tableSelected: [], // 当前所选中表格行数据
      otherFilters: [], // 表格额外查询条件
      tableConfig: {
        interfacePath: `${process.env.VUE_APP_BASE_API}/api/v1/userSearchKeywordRecord/page`,
        onlySearchBar: false,
        pageSize: 20,
        sort: 'createTime',
        order: 'desc',
        setting: [
          {
            prop: 'keyWord',
            label: '关键词',
            minWidth: 150
          },
          {
            prop: 'client',
            label: '来源系统',
            minWidth: 150,
            type: 'select',
            propEnum: {
              domainCode: 'marketing',
              appCode: 'sad',
              dictTypeCode: 'KEYWORD_SOURCE'
            }
          },
          {
            prop: 'type',
            label: '搜索类型',
            minWidth: 150,
            type: 'select',
            propEnum: {
              list: [
                { dictCode: 'PRODUCT', dictName: '商品' },
                { dictCode: 'SERIES', dictName: '系列' },
                { dictCode: 'SCHEMAL', dictName: '方案' },
                { dictCode: 'ATLAS', dictName: '图册' }
              ]
            }
          },
          {
            prop: 'createBy',
            label: '创建人',
            minWidth: 150
          },
          {
            prop: 'createTime',
            label: '创建时间',
            minWidth: 150,
            type: 'date',
            formatData: ({ createTime }) => {
              return parseTime(createTime)
            }
          }],
        btnList: !this.isProduction ? [
          {
            buttonName: '导出',
            optCode: 'export',
            outerFlag: true
          }] : null
      },

      exportVisible: false,
      exportConfig: [
        {
          code: 'exportCustomerList',
          name: '关键字搜索统计',
          async: false, // 是否异步
          dataApi: `${process.env.VUE_APP_BASE_API}/api/v1/userSearchKeywordRecord/export`,
          filtersRaw: [],
          paramsRaw: {},
          selectedRows: [], // 当前所选中的数据航
          queryField: 'id'// 指定行导出的字段名称
        }
      ]
    }
  },

  computed: {},

  created() {},
  activated() {},

  mounted() {},

  methods: {
    btnOperate(code) {
      switch (code) {
        case 'export':
          this.handleExport()
          break
        default:
          break
      }
    },
    // 刷新表格数据
    refreshTable(isInit) {
      this.$nextTick(() => {
        this.$refs.refTable.initTableData(isInit ? '' : 'onPage')
      })
    },
    // 导出
    handleExport() {
      const allFilters = this.$refs.refTable.getAllFilters()
      const { searchBarFilter } = allFilters
      this.exportVisible = true
      this.exportConfig.forEach(item => {
        if (item.dataApi) {
          // item.selectedRows = this.tableSelected
          item.filtersRaw = [...this.otherFilters, ...searchBarFilter]
        }
      })
    }
  }
}

</script>
<style lang='scss' scoped>
</style>
